home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Chat & Communication
/
Digsby build 37
/
digsby_setup.exe
/
lib
/
socket.pyo
(
.txt
)
< prev
next >
Wrap
Python Compiled Bytecode
|
2008-10-13
|
10KB
|
411 lines
# Source Generated with Decompyle++
# File: in.pyo (Python 2.5)
import _socket
from _socket import *
_have_ssl = False
try:
import _ssl
from _ssl import *
_have_ssl = True
except ImportError:
pass
import os
import sys
try:
from cStringIO import StringIO
except ImportError:
from StringIO import StringIO
try:
from errno import EBADF
except ImportError:
EBADF = 9
__all__ = [
'getfqdn']
__all__.extend(os._get_exports_list(_socket))
if _have_ssl:
__all__.extend(os._get_exports_list(_ssl))
_realsocket = socket
if _have_ssl:
_realssl = ssl
def ssl(sock, keyfile = None, certfile = None):
if hasattr(sock, '_sock'):
sock = sock._sock
return _realssl(sock, keyfile, certfile)
if sys.platform.lower().startswith('win'):
errorTab = { }
errorTab[10004] = 'The operation was interrupted.'
errorTab[10009] = 'A bad file handle was passed.'
errorTab[10013] = 'Permission denied.'
errorTab[10014] = 'A fault occurred on the network??'
errorTab[10022] = 'An invalid operation was attempted.'
errorTab[10035] = 'The socket operation would block'
errorTab[10036] = 'A blocking operation is already in progress.'
errorTab[10048] = 'The network address is in use.'
errorTab[10054] = 'The connection has been reset.'
errorTab[10058] = 'The network has been shut down.'
errorTab[10060] = 'The operation timed out.'
errorTab[10061] = 'Connection refused.'
errorTab[10063] = 'The name is too long.'
errorTab[10064] = 'The host is down.'
errorTab[10065] = 'The host is unreachable.'
__all__.append('errorTab')
def getfqdn(name = ''):
name = name.strip()
if not name or name == '0.0.0.0':
name = gethostname()
try:
(hostname, aliases, ipaddrs) = gethostbyaddr(name)
except error:
pass
aliases.insert(0, hostname)
for name in aliases:
if '.' in name:
break
continue
else:
name = hostname
return name
_socketmethods = ('bind', 'connect', 'connect_ex', 'fileno', 'listen', 'getpeername', 'getsockname', 'getsockopt', 'setsockopt', 'sendall', 'setblocking', 'settimeout', 'gettimeout', 'shutdown')
if sys.platform == 'riscos':
_socketmethods = _socketmethods + ('sleeptaskw',)
_delegate_methods = ('recv', 'recvfrom', 'recv_into', 'recvfrom_into', 'send', 'sendto')
class _closedsocket(object):
__slots__ = []
def _dummy(*args):
raise error(EBADF, 'Bad file descriptor')
send = recv = recv_into = sendto = recvfrom = recvfrom_into = _dummy
__getattr__ = _dummy
class _socketobject(object):
__doc__ = _realsocket.__doc__
__slots__ = [
'_sock',
'__weakref__'] + list(_delegate_methods)
def __init__(self, family = AF_INET, type = SOCK_STREAM, proto = 0, _sock = None):
if _sock is None:
_sock = _realsocket(family, type, proto)
self._sock = _sock
for method in _delegate_methods:
setattr(self, method, getattr(_sock, method))
def close(self):
self._sock = _closedsocket()
dummy = self._sock._dummy
for method in _delegate_methods:
setattr(self, method, dummy)
close.__doc__ = _realsocket.close.__doc__
def accept(self):
(sock, addr) = self._sock.accept()
return (_socketobject(_sock = sock), addr)
accept.__doc__ = _realsocket.accept.__doc__
def dup(self):
return _socketobject(_sock = self._sock)
def makefile(self, mode = 'r', bufsize = -1):
return _fileobject(self._sock, mode, bufsize)
family = property((lambda self: self._sock.family), doc = 'the socket family')
type = property((lambda self: self._sock.type), doc = 'the socket type')
proto = property((lambda self: self._sock.proto), doc = 'the socket protocol')
_s = 'def %s(self, *args): return self._sock.%s(*args)\n\n%s.__doc__ = _realsocket.%s.__doc__\n'
for _m in _socketmethods:
exec _s % (_m, _m, _m, _m)
del _m
del _s
socket = SocketType = _socketobject
class _fileobject(object):
default_bufsize = 8192
name = '<socket>'
__slots__ = [
'mode',
'bufsize',
'softspace',
'_sock',
'_rbufsize',
'_wbufsize',
'_rbuf',
'_wbuf',
'_close']
def __init__(self, sock, mode = 'rb', bufsize = -1, close = False):
self._sock = sock
self.mode = mode
if bufsize < 0:
bufsize = self.default_bufsize
self.bufsize = bufsize
self.softspace = False
if bufsize == 0:
self._rbufsize = 1
elif bufsize == 1:
self._rbufsize = self.default_bufsize
else:
self._rbufsize = bufsize
self._wbufsize = bufsize
self._rbuf = StringIO()
self._wbuf = []
self._close = close
def _getclosed(self):
return self._sock is None
closed = property(_getclosed, doc = 'True if the file is closed')
def close(self):
try:
if self._sock:
self.flush()
finally:
if self._close:
self._sock.close()
self._sock = None
def __del__(self):
try:
self.close()
except:
pass
def flush(self):
if self._wbuf:
buffer = ''.join(self._wbuf)
self._wbuf = []
self._sock.sendall(buffer)
def fileno(self):
return self._sock.fileno()
def write(self, data):
data = str(data)
if not data:
return None
self._wbuf.append(data)
if not self._wbufsize == 0:
if self._wbufsize == 1 or '\n' in data or self._get_wbuf_len() >= self._wbufsize:
self.flush()
def writelines(self, list):
self._wbuf.extend(filter(None, map(str, list)))
if self._wbufsize <= 1 or self._get_wbuf_len() >= self._wbufsize:
self.flush()
def _get_wbuf_len(self):
buf_len = 0
for x in self._wbuf:
buf_len += len(x)
return buf_len
def read(self, size = -1):
rbufsize = max(self._rbufsize, self.default_bufsize)
buf = self._rbuf
buf.seek(0, 2)
if size < 0:
self._rbuf = StringIO()
while True:
data = self._sock.recv(rbufsize)
if not data:
break
buf.write(data)
return buf.getvalue()
else:
buf_len = buf.tell()
if buf_len >= size:
buf.seek(0)
rv = buf.read(size)
self._rbuf = StringIO()
self._rbuf.write(buf.read())
return rv
self._rbuf = StringIO()
while True:
left = size - buf_len
data = self._sock.recv(left)
if not data:
break
n = len(data)
if n == size and not buf_len:
return data
if n == left:
buf.write(data)
del data
break
buf.write(data)
buf_len += n
del data
return buf.getvalue()
def readline(self, size = -1):
buf = self._rbuf
buf.seek(0, 2)
if buf.tell() > 0:
buf.seek(0)
bline = buf.readline(size)
if bline.endswith('\n') or len(bline) == size:
self._rbuf = StringIO()
self._rbuf.write(buf.read())
return bline
del bline
if size < 0:
if self._rbufsize <= 1:
buf.seek(0)
buffers = [
buf.read()]
self._rbuf = StringIO()
data = None
recv = self._sock.recv
while data != '\n':
data = recv(1)
if not data:
break
buffers.append(data)
return ''.join(buffers)
buf.seek(0, 2)
self._rbuf = StringIO()
while True:
data = self._sock.recv(self._rbufsize)
if not data:
break
nl = data.find('\n')
if nl >= 0:
nl += 1
buf.write(buffer(data, 0, nl))
self._rbuf.write(buffer(data, nl))
del data
break
buf.write(data)
return buf.getvalue()
else:
buf.seek(0, 2)
buf_len = buf.tell()
if buf_len >= size:
buf.seek(0)
rv = buf.read(size)
self._rbuf = StringIO()
self._rbuf.write(buf.read())
return rv
self._rbuf = StringIO()
while True:
data = self._sock.recv(self._rbufsize)
if not data:
break
left = size - buf_len
nl = data.find('\n', 0, left)
if nl >= 0:
nl += 1
self._rbuf.write(buffer(data, nl))
if buf_len:
buf.write(buffer(data, 0, nl))
break
else:
return data[:nl]
n = len(data)
if n == size and not buf_len:
return data
if n >= left:
buf.write(buffer(data, 0, left))
self._rbuf.write(buffer(data, left))
break
buf.write(data)
buf_len += n
return buf.getvalue()
def readlines(self, sizehint = 0):
total = 0
list = []
while True:
line = self.readline()
if not line:
break
list.append(line)
total += len(line)
if sizehint and total >= sizehint:
break
continue
return list
def __iter__(self):
return self
def next(self):
line = self.readline()
if not line:
raise StopIteration
return line